home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 7722 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  2.7 KB

  1. Path: gwen.pcug.co.uk!altheim!broldham
  2. Newsgroups: comp.lang.c
  3. Message-ID: <1177@altheim.win-uk.net>
  4. References: <4gqpa1$3h9@alcor.usc.edu> <4gsdno$1bg@umbc9.umbc.edu> <4gtab6$acb@ceylon.gte.com><313318b8.53776146@nntp.ix.netcom.com>
  5. Reply-To: broldham@altheim.win-uk.net (Brian R. Oldham)
  6. From: broldham@altheim.win-uk.net (Brian R. Oldham)
  7. Date: Wed, 28 Feb 1996 13:12:52 GMT
  8. Subject: Re: What is &Variable (declared as: char Variable[10])?
  9.  
  10.  
  11. In article <313318b8.53776146@nntp.ix.netcom.com>, Mike Rubenstein (miker3@ix.netcom.com) writes:
  12. >Brenda <g051286> wrote:
  13. >
  14. >> schlein@umbc.edu (Jonas J. Schlein) wrote:
  15. >> >Abu Wawda <wawda@alcor.usc.edu> wrote:
  16. >> >|> I'm having trouble understanding what the address of a static array
  17. >> >|> is.
  18. >> >
  19. >> >I'm having trouble understanding why it matters? You almost never use the
  20. >> >address of an array directly unless doing something tricky with pointers
  21. >> >or with particular dimensions of a multiple dimensional array.
  22. >> >
  23. >> >|> For example, if I declare a variable called myarray as:
  24. >> >|>  char myarray[10];
  25. >> >|> then what could &myarray possibly mean? myarray is not a pointer, so
  26. >> >|> &myarray could not possibly be the address of the variable myarray
  27. >> >|> (like it would be if I did char* myarray and then asked for &myarray).
  28. >> >
  29. >> >Yes it could and yes it is...'myarray' is not a pointer, but &myarray is
  30. >> >a pointer to 'myarray'.
  31. >> 
  32. >> Um, that's not correct.  myarray is DEFINITELY a pointer!  As declared above,
  33. >> it is a constant pointer to 10 contiguous char datatypes.  myarray is an
  34. >> ADDRESS whereas *(myarray + 5) or myarray[5] is the 6th element in the array.
  35. >> The difference between an array and something like "char *p=myarray", is that
  36. >> you can say p++, but you can't say myarray++.  You shouldn't say &myarray
  37. >> either because myarray is a constant, but I read that on some compilers
  38. >> scanf ignores the dereferencing and does not bother to warn you.
  39. >
  40. >NO. NO. NO.  Where do people get this idea that arrays are pointers.
  41. >Arrays are arrays and pointers are pointers.  In many, but not all,
  42. >situations an array is converted to a pointer.  There are exceptions.
  43. >For example sizeof myarray is 10 but sizeof p is almost certainly not
  44. >10.
  45. >
  46. >Why shouldn't you say &myarray.  It's perfectly legal C and any
  47. >compiler that does not accept it is broken.  &myarray is a pointer to
  48. >an array of 10 char.
  49. >
  50. >
  51. >Michael M Rubenstein
  52. >
  53.  
  54. I think Brenda is right. No-one has said that arrays are pointers, but
  55. the name of an array is. It is the address of the first element of an
  56. array. My understanding is that &myarray is allowable in C++, but not
  57. in C. Anyone confirm this?
  58.  
  59.  
  60. ---
  61. Brian Oldham
  62. Hucknall UK
  63. !...Gesundbrunnen
  64.  
  65.  
  66.  
  67.  
  68.  
  69.  
  70.  
  71.  
  72.